//二级页面的manage页面的js代码

//获取头部卡密按钮
let carmi = document.getElementById('carmi');
//获取头部销售单号按钮
let sales = document.getElementById('sales');
//获取输入span元素
let enter = document.getElementById('enter');
//获取卡号span元素
let cardnumber = document.getElementById('cardnumber');
//获取提示语元素
let bottom_text = document.getElementById('bottom_text');
//获取输入input元素
let input_enter = document.getElementById('input_enter');
//获取卡号input元素
let input_cardnumber = document.getElementById('input_cardnumber');

//卡密按钮点击事件
let sales_flag = 1
carmi.onclick = function() {
    sales_flag = 1
    this.style.color = '#fff'
    this.style.backgroundColor = '#00A862'
    sales.style.color = '#00A862'
    sales.style.backgroundColor = '#F7F7F7'
    bottom_text.innerText = '请输入你的星礼卡卡号和密码查询星礼卡余额以及交易记录'
    enter.innerText = '输入密码'
}

//销售单号按钮点击事件

sales.onclick = function() {
    sales_flag = 0
    this.style.color = '#fff'
    this.style.backgroundColor = '#00A862'
    carmi.style.color = '#00A862'
    carmi.style.backgroundColor = '#F7F7F7'
    bottom_text.innerText = '请输入你的星礼卡卡号和激活小票上的销售单号查询星礼卡余额以及交易记录'
    enter.innerText = '销售单号'
}

//卡号input点击事件
input_cardnumber.onclick = function() {
    cardnumber.style.fontSize = '12px'
    cardnumber.style.top = '0px'
    enter.style.fontSize = '16px'
    enter.style.top = '10px'
    this.style.borderBottomColor = '#00a862'
    input_enter.style.borderBottomColor = '#e8e8e8'
}

//输入input点击事件
input_enter.onclick = function() {
    enter.style.fontSize = '12px'
    enter.style.top = '0px'
    cardnumber.style.fontSize = '16px'
    cardnumber.style.top = '10px'
    this.style.borderBottomColor = '#00a862'
    input_cardnumber.style.borderBottomColor = '#e8e8e8'
}






$(function() {
    var nc_token = ["CF_APP_1", (new Date()).getTime(), Math.random()].join(':');
    var yzflag
    var NC_Opt = {
        renderTo: "#your-dom-id",
        appkey: "CF_APP_1",
        scene: "register",
        token: nc_token,
        customWidth: 400,
        trans: {
            "key1": "code0"
        },
        elementID: ["usernameID"],
        is_Opt: 0,
        language: "cn",
        isEnabled: true,
        timeout: 3000,
        times: 5,
        apimap: {
            // 'analyze': '//a.com/nocaptcha/analyze.jsonp',
            // 'get_captcha': '//b.com/get_captcha/ver3',
            // 'get_captcha': '//pin3.aliyun.com/get_captcha/ver3'
            // 'get_img': '//c.com/get_img',
            // 'checkcode': '//d.com/captcha/checkcode.jsonp',
            // 'umid_Url': '//e.com/security/umscript/3.2.1/um.js',
            // 'uab_Url': '//aeu.alicdn.com/js/uac/909.js',
            // 'umid_serUrl': 'https://g.com/service/um.json'
        },
        callback: function(data) {
            yzflag = true
            if ($('#input_cardnumber').val() != '' && $('#input_enter').val() != '') {
                $('#btn').removeAttr("disabled");
                $('#btn').css({
                    'background': '#00A862',
                    'border': '0',
                    'color': '#fff',
                    'cursor': 'pointer'
                })
            } else {
                $('#btn').css({
                    'background': '#f7f7f7',
                    'border -color': '#f7f7f7',
                    'color': 'rgba(0, 0, 0, 0.38)',
                    'cursor': 'not-allowed'
                })
                $('#btn').attr("disabled", "disabled");
            }


        }
    }
    var nc = new noCaptcha(NC_Opt)

    nc.upLang('cn', {
        _startTEXT: "请按住滑块，拖动到最右边",
        _yesTEXT: "验证通过",
        _error300: "哎呀，出错了，点击<a href=\"javascript:__nc.reset()\">刷新</a>再来一次",
        _errorNetwork: "网络不给力，请<a href=\"javascript:__nc.reset()\">点击刷新</a>",
    })
    $('.contentbox input').each(function(index, i) {
        $(i).bind("input propertychange", function() {
            if ($('#input_cardnumber').val() != '' && $('#input_enter').val() != '' && yzflag == true) {
                $('#btn').removeAttr("disabled");
                $('#btn').css({
                    'background': '#00A862',
                    'border': '0',
                    'color': '#fff',
                    'cursor': 'pointer'
                })
            } else {
                $('#btn').css({
                    'background': '#f7f7f7',
                    'border -color': '#f7f7f7',
                    'color': 'rgba(0, 0, 0, 0.38)',
                    'cursor': 'not-allowed'
                })
                $('#btn').attr("disabled", "disabled");
            }

        })
    })
    $('#btn').click(function() {
        if (sales_flag == 1) {
            $.ajax({
                method: "post",
                url: "/manage_password",
                data: {
                    id: $("#input_cardnumber").val(),
                    password: $("#input_enter").val()
                },
                success: function(data) {
                    data = JSON.parse(JSON.stringify(data))
                        // console.log(data.jg.id);
                    alert(`您的余额还剩${data.jg.balance}元`)
                    if (data.code == 200) {
                        location.href = '/'
                    }
                },
                fail: function(err) {
                    console.log(err);
                }
            })
        } else {
            $.ajax({
                method: "post",
                url: "/manage_code",
                data: {
                    id: $("#input_cardnumber").val(),
                    code: $("#input_enter").val()
                },
                success: function(data) {
                    data = JSON.parse(JSON.stringify(data))
                    alert(`您的余额还剩${data.jg.balance}元`)
                    if (data.code == 200) {
                        location.href = '/'
                    }
                },
                fail: function(err) {
                    console.log(err);
                }
            })
        }

    })
})